#!/usr/bin/lua -f
s=arg[0] while strsub(s,-1)~="/" do s=strsub(s,1,-2) end dofile(s.."common.lua")
POS=8
HDL=openfile(arg[1],"rb")
while POS do
	RC=seek(HDL, "set", POS)
	INF=read(HDL,60)
	if not INF then break end
	NAM=strsub(INF,1,16)
	LEN=tonumber(strsub(INF,49,58))
	POS=POS+60
	HDL2=openfile(NAM,"wb")
	REMAINING=LEN
	while REMAINING > 0 do
		BUF=read(HDL,min(REMAINING,16384))
		if not BUF then break end
		REMAINING=REMAINING-strlen(BUF)
		write(HDL2,BUF)
	end	
	closefile(HDL2)
	print("file: "..NAM.." size: "..LEN)
	POS=POS+LEN+mod(LEN,2)
end
closefile(HDL)
